package com.link2room.rodimus.service.impl;

import com.link2room.common.dto.result.base.MemberSessionDto;
import com.link2room.common.dto.threadlocal.ApiThreadLocal;
import com.link2room.common.exception.SysException;
import com.link2room.common.util.JacksonUtil;
import com.link2room.common.util.StringUtil;
import com.link2room.rodimus.dto.param.inside.MemberPackageInsideParamDto;
import com.link2room.rodimus.dto.result.base.DrawPrizeBaseDto;
import com.link2room.rodimus.entity.DrawPrizeBaseEntity;
import com.link2room.rodimus.entity.MemberBase;
import com.link2room.rodimus.feign.soundwave.PmsMemberFeignService;
import com.link2room.rodimus.service.IAfterDrawHandleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


import javax.transaction.NotSupportedException;

import static com.link2room.enums.exception.RodimusSysExceptionEnum.DRAW_ERROR;

/**
 * Created by LN on 2017/10/26
 */
@Component("packageAfterDrawHandleService")
public class AfterDrawHandlePMSPackageServiceImpl extends AbstractArfterDrawHandlerServiceImpl implements IAfterDrawHandleService {

    @Autowired
    private PmsMemberFeignService pmsMemberFeignService;

    @Override
    void doAfterDraw(DrawPrizeBaseDto drawPrizeBaseDto) throws Exception {
        String rule = drawPrizeBaseDto.getRule();
        if (StringUtil.isBlank(rule)) {
            throw new SysException(DRAW_ERROR, "奖项未配置.[prizeCode ] " + drawPrizeBaseDto.getCode());
        }
        MemberPackageInsideParamDto paramDto = JacksonUtil.jsonToBean(rule, MemberPackageInsideParamDto.class);
        MemberSessionDto memberSession = ApiThreadLocal.getMemberSessionThreadLocal();
        String memberNo = memberSession.getMemberNo();
        String lhotelGroupCode = memberSession.getLhotelGroupCode();
        paramDto.setL2rMemberNo(memberNo);
        paramDto.setOrderNo(drawPrizeBaseDto.getDrawNo());
        paramDto.setLhotelGroupCode(lhotelGroupCode);
        pmsMemberFeignService.exchangePackage(paramDto);
    }



    @Override
    void redoAfterDraw(MemberBase memberBase, String openid, DrawPrizeBaseEntity prizeBase) throws Exception {
        throw new NotSupportedException("packageAfterDrawHandleService 没有实现 redoAfterDraw");
    }


}
